import { ManageCommonAPI } from '@/pages/type';
import { Button } from 'antd';
import { Fragment } from 'react';
import { ColumnsRenderFun, stateOfRendering, statusOfRendering } from '../common/Format';
import { DeptRatioManageAPI } from '../common/type';
import { EyeOutlined } from '@ant-design/icons';
import { tableMoreBtnConfig } from '@/utils/myutilConfig';

/**操作按钮的显示*/
const Operation = (curRes: Record<string, any>, operateFuns: DeptRatioManageAPI.IOperateAPI, record: Record<string, any>) => {
  let operationArray: any = [];

  /** 一个按钮都没有时展示*/
  const Disable = (
    <Fragment key={record?.id + '--Disable'}>
      <Button style={{ color: '#000' }} className="manageBtntTxtStyle" type={'link'} size={'small'} disabled>
        --
      </Button>
    </Fragment>
  );

  /** 更多按钮配置 */
  const otherBtnConfig: ManageCommonAPI.TableMoreBtnConfigApi[] = [
    {
      icon: <EyeOutlined />,
      btnName: '查看',
      clickFnc: operateFuns,
      clickType: 'onView',
      isVisible: true,
    },
  ];
  const ohterBtn = tableMoreBtnConfig(otherBtnConfig, record);
  operationArray = ohterBtn;
  operationArray = operationArray?.filter((itemBtn: any) => itemBtn);
  return operationArray && operationArray?.length > 0 ? operationArray : [Disable];
};

/**
 * 管理页表格配置
 * */
export const ManageTableSwitch = (curRes: Record<string, any>, operateFuns: DeptRatioManageAPI.IOperateAPI) => {
  return [
    {
      title: '日志编号',
      dataIndex: 'operId',
      key: 'operId',
      width: 140,
      visible: true,
      unDrag: true,
      fixed: 'left',
      sorter: (a: any, b: any) => (a?.id > b?.id ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text, wordNum: 100 }),
    },
    {
      title: '系统模块',
      dataIndex: 'title',
      key: 'title',
      visible: true,
      width: 180,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.title > b?.title ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '操作类型',
      dataIndex: 'businessType',
      key: 'businessType',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.businessType > b?.businessType ? 1 : -1),
      render: (text: string | number) => stateOfRendering(text),
    },
    {
      title: '请求方式',
      dataIndex: 'requestMethod',
      key: 'requestMethod',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.requestMethod > b?.requestMethod ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '操作人员',
      dataIndex: 'operName',
      key: 'operName',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.operName > b?.operName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '主机',
      dataIndex: 'operIp',
      key: 'operIp',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.operIp > b?.operIp ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '操作地点',
      dataIndex: 'operLocation',
      key: 'operLocation',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.operLocation > b?.operLocation ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '操作状态',
      dataIndex: 'status',
      key: 'status',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.status > b?.status ? 1 : -1),
      render: (text: string | number) => statusOfRendering(text),
    },
    {
      title: '操作日期',
      dataIndex: 'operTime',
      key: 'operTime',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.operTime > b?.operTime ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '操作',
      dataIndex: 'operation',
      key: 'operation',
      width: 150,
      visible: true,
      unDrag: true,
      fixed: 'right',
      render: (text: string | null, record: Record<string, any>) => {
        return <div style={{ display: 'flex' }}>{Operation(curRes, operateFuns, record)}</div>;
      },
    },
  ];
};
